package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.DetectionAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetDiagnosticCar;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import pl.droidsonroids.gif.AnimationListener;
import pl.droidsonroids.gif.GifDrawable;
import pl.droidsonroids.gif.GifImageView;

/**
 * Created by Administrator on 2016/3/11.
 */
public class DetectionActivity extends JTActivity implements View.OnClickListener{

    private TextView title_name;

    private List<GetDiagnosticCar.Detection> list = new ArrayList<>();

    private String score;

    private GifImageView animImg;

    private GifDrawable gifDrawable;


    private GetDiagnosticCar getDiagnosticCar = new GetDiagnosticCar(new AsyCallBack<GetDiagnosticCar.Info>() {


        @Override
        public void onStart(int type) throws Exception {


        }

        @Override
        public void onSuccess(String toast, int type, final GetDiagnosticCar.Info info) throws Exception {

            if(info.msg.equals("000")) {

                score = info.score;

                JTApplication.jtPreferences.saveScore(score);

                if (!score.equals("100")) {

                    list.addAll(info.list);

                }

            }else {

                gifDrawable.stop();

                UtilToast.show(context,info.msg);

            }
        }

    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_detection);

        init_view();

        getDiagnosticCar.execute(this);
    }

    private void init_view() {

//        (title_name = (TextView) findViewById(R.id.tv_detection_result_title)).setText("检测");

        animImg = (GifImageView) findViewById(R.id.gif_detection);

        animImg.setImageResource(R.mipmap.detection);

        gifDrawable = (GifDrawable) animImg.getDrawable();

        gifDrawable.setSpeed(1.0f);

        gifDrawable.addAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationCompleted(int loopNumber) {

                ToResultAct();

            }
        });

    }
    private void ToResultAct(){

        Intent intent = new Intent(DetectionActivity.this,DetectionResultActivity.class);

        Bundle bundle = new Bundle();

        if(list.size()==0){
            bundle.putString("flag","0");
        }else{
            bundle.putString("flag","1");
        }

        bundle.putSerializable("list",(Serializable) list);

        intent.putExtras(bundle);

        startActivity(intent);

        finish();

    }
}
